package com.hzhr.iot.user.dao.helper;

import com.hzhr.iot.user.dao.UserInRoleDao;
import com.hzhr.iot.user.entity.UserInRoleEntity;
import com.hzhr.iot.user.queryModel.custom.UserInRoleCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserInRoleDaoHelper {
    @Autowired
    UserInRoleDao userInRoleDao;

    public int getCountByUserIdAndRoleId(int userId, int roleId) {
        UserInRoleCustomQueryModel userInRoleCustomQueryModel = new UserInRoleCustomQueryModel();
        userInRoleCustomQueryModel.setEqual_userId(userId);
        userInRoleCustomQueryModel.setEqual_roleId(roleId);
        int count = userInRoleDao.selectCount(userInRoleCustomQueryModel);
        return count;
    }

    public UserInRoleEntity getByUserId(int userId) {
        UserInRoleCustomQueryModel userInRoleCustomQueryModel = new UserInRoleCustomQueryModel();
        userInRoleCustomQueryModel.setEqual_userId(userId);
        userInRoleCustomQueryModel.setShow(true);
        UserInRoleEntity userInRoleEntity = userInRoleDao.selectEntity(userInRoleCustomQueryModel);
        return userInRoleEntity;
    }

    public UserInRoleEntity getByUserIdAndOrderByRoleId(int userId, String orderBy_roleId) {
        UserInRoleCustomQueryModel userInRoleCustomQueryModel = new UserInRoleCustomQueryModel();
        userInRoleCustomQueryModel.setEqual_userId(userId);
        userInRoleCustomQueryModel.setOrderBy_roleId(orderBy_roleId);
        userInRoleCustomQueryModel.setShow(true);
        UserInRoleEntity userInRoleEntity = userInRoleDao.selectEntity(userInRoleCustomQueryModel);
        return userInRoleEntity;
    }
}
